package com.chief.hadoop.mr.outputFormat;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReduce extends Reducer<Text, FlowBean, Text, FlowBean> {

    FlowBean flowBean = new FlowBean();

    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        Integer cnt = 0;
        Long total = 0L;
        for (FlowBean value : values) {
            total += value.getTotal();
            cnt += value.getCnt();
        }
        flowBean.setTotal(total);
        flowBean.setCnt(cnt);

        context.write(key, flowBean);
    }
}
